<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport"
        content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0">
    <title>版本更新日志</title>
    <link rel="stylesheet" href="./updatelog.css">
    <script src="./lib/axios.js"></script>
    <script src="./lib/media_750.js"></script>
</head>

<body>
    <div class="page">
        <div class="content">
        </div>
        <div class="label">
            <span class="text_lodText"></span>
        </div>
    </div>
    </div>

    <script>
        let list = document.getElementsByClassName('content')[0];
        let id
        let mode
        let content
        let pageNo = 1
        let pageSize = 10
        let total = null
        let isLoadding = false;
        let LoadText = document.querySelector('.text_lodText')
        const currentUrl = window.location.href
        GetRequest(currentUrl)
        this.getList()
        function itemSes(e, v) {
            localStorage.setItem("setCon", JSON.stringify(v));
            location.href = `./details.html?mode=${mode}`
        }
        function GetRequest(urlStr) {
            if (typeof urlStr == "undefined") {
                var url = decodeURI(location.search); //获取url中"?"符后的字符串
            } else {
                var url = "?" + urlStr.split("?")[1];
            }
            var theRequest = new Object();
            if (url.indexOf("?") != -1) {
                var str = url.substr(1);
                strs = str.split("&");
                for (var i = 0; i < strs.length; i++) {
                    theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);

                }
            }
            mode = theRequest.mode
        }


        function myReplaceOne(sInput, sChar, sReplaceChar) {
            if (sInput == "" || sInput == undefined) {
                return "";
            }

            return sInput.replace(sChar, sReplaceChar);
        }
        if (mode == 'black') {
            var head = document.getElementsByTagName('HEAD').item(0);
            var style = document.createElement('link');
            style.href = './black.css';
            style.rel = 'stylesheet'
            style.type = 'text/css';
            head.appendChild(style);


        } else if (mode == 'white') {
            var head = document.getElementsByTagName('HEAD').item(0);
            var style = document.createElement('link');
            style.href = './updatelog.css';
            style.rel = 'stylesheet'
            style.type = 'text/css';
            head.appendChild(style);
        }

        function formatDate(date) {
            var date = new Date(date);
            var YY = date.getFullYear();
            var MM = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
            var DD = (date.getDate() < 10 ? '0' + (date.getDate()) : date.getDate());
            var hh = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
            var mm = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
            var ss = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
            return YY + '年' + MM + "月" + DD + '日'
        }

        // 防抖
        function debounce(func, wait, immediate) {
            var timeout;
            return function () {
                var context = this, args = arguments;
                var later = function () {
                    timeout = null;
                    if (!immediate) func.apply(context, args);
                };
                var callNow = immediate && !timeout;
                clearTimeout(timeout);
                timeout = setTimeout(later, wait);
                if (callNow) func.apply(context, args);
            };
        };
        var bottomOut = debounce(function (e) {
            const { scrollHeight, clientHeight, scrollTop } = e.target;
            if (scrollHeight - clientHeight - scrollTop < 50) {
                // 滚动条触底了
                // 判断现在有没有请求 
                if (total == 0 || total < 10) {
                    LoadText.innerHTML = '暂无更多数据'
                    return
                }
                isLoadding = true;
                LoadText.innerHTML = '加载中...'
                pageNo += 1
                getList();
            }
        }, 300)
        document.querySelector(".page").addEventListener("scroll", bottomOut)

        function getList() {
            axios({
                url: `/api/im/app/updateLog/limit?pageNo=${pageNo}&pageSize=${pageSize}`
            }).then(res => {
                total = res.data.total
                let data = res.data.rows;
                data.forEach(item => {
                    item.createTime = formatDate(item.createTime)
                    var ch = "\r\n";
                    item.content = item.content.replace(new RegExp(ch, 'g'), "</br>")
                    list.innerHTML += `<div onclick='itemSes(event, ${JSON.stringify(item.content)})' class="item"><div class="lanel">
                    <div div class="name" > WedoTalk${item.version}主要更新</div >
                        <div class="time">${item.createTime}</div>
            </div > <img class="icon_ri" src="./lib/img/arrow_ic_right_grey.png" alt="" /> </div > `

                });
            }).catch(function (error) {
                console.log(error);

            });
        }
    </script>
</body>

</html>